#include <iostream>

using namespace std;
const int N=35;
int dp[N][N];
int g[N][N];

int n;
int a[N];
void dfs(int left,int right)
{
	if(left>right)
		return;
	cout<<g[left][right]<<' ';
	dfs(left,g[left][right]-1);
	dfs(g[left][right]+1,right);
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	
	for(int len=1;len<=n;len++)
	{
		for(int l=1;l+len-1<=n;l++)
		{
			int r=l+len-1;
			if(len==1)
			{
				dp[r][r]=a[r];
				g[l][r]=l;
			}
			else{
				for(int k=l;k<=r;k++)
				{
					int left=k==l?1:dp[l][k-1];
					int right=k==r?1:dp[k+1][r];
					int score=left*right+a[k];
					if(score>dp[l][r])
					{
						g[l][r]=k;
						dp[l][r]=score;
					}
				}
			}
		}
	}
	cout<<dp[1][n]<<endl;
	dfs(1,n);
	return 0;
}
